<template>
    <div id="program">
        <header>
            <div class="P_date">
                <span>时间：</span>
                <gDate @faithDate="faithDate"></gDate>
            </div>
            <div class="P_type">
                <div class="Choice">
                    <el-form ref="form" prop="">
                        <span>搜索：</span>
                        <el-form-item>
                            <el-input v-model="searchData"></el-input>
                        </el-form-item>
                        <el-button @click="search">搜索</el-button>
                    </el-form>
                </div>
            </div>
            <el-button type="primary" class="addBtn" @click="addBtn">添加</el-button>
        </header>
        <main>
            <el-table :data="tableData" border style="width: 100%" stripe>
                <el-table-column prop="appname" label="小程序名称"></el-table-column>
                <el-table-column prop="appid" label="ID"></el-table-column>
                <el-table-column prop="createtime" label="添加时间"></el-table-column>
                <el-table-column label="操作">
                    <template slot-scope="scope">
                        <el-button @click="modifyClick(scope.row.appid)" type="text" size="small">修改</el-button>
                        <el-button type="text" size="small" @click="removeClick(scope.row.appid)">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="currPage">
                <el-pagination
                    layout="prev, pager, next"
                    :page-size=pageSize
                    :current-page=currentPage
                    @current-change="handleCurrentChange"
                    :total=total>
                </el-pagination>
            </div>
        </main>
    </div>
</template>

<script>
import Vue from 'vue'
import programModify  from '../modify/programModify'
import programAdd  from '../add/programAdd'
import gDate from '../G_Date/gdate'
import { iframe,addList,ModifyList,RemoteList,DataList,getChannel } from '@/assets/js'
export default {
     components:{
        gDate
    },
    data(){
        return {
            pageSize:2,
            searchData: '',//搜索内容
            total:0,//默认数据总数
            currentPage:1,//默认开始页面
            tableData: []
        }
    },
    methods:{
        faithDate:function(e){//时间组件
            this.userDate = e;
        },
        addBtn:function(e){//新增
            addList(this,programAdd)
        },
        modifyClick:function(e){//修改
            let obj = {}
            this.tableData.map((item,index)=>{
                if(item.appid == e){
                    obj.AppName = item.appname
                    obj.APPID = e
                    return obj
                }
            })
            
            ModifyList(this,obj,programModify)
        },
        removeClick:function(e){//删除
            let data = {
                appid:e
            }
           RemoteList(this,data,e,"program/delProgram")
        },
        handleCurrentChange:function(e){//点击分页
            this.currentPage = e
            this.CurrData()
        },
        
        search:function(){//搜索
            this.currentPage = 1
            this.CurrData()
        },
        CurrData:function(){//分页
            let data = {
               startTime:this.userDate?this.userDate[0]:'',
               endTime:this.userDate?this.userDate[1]:'',
               appname:this.searchData,
               page:this.currentPage
            }
            DataList(this,data,'program/programList')
        }
        
        
    },
    mounted:function(){
        this.CurrData()
    }
}
</script>


